package hu.diploma.android.util;

import hu.diploma.android.serviceimpl.CallsServiceImpl;
import hu.diploma.android.serviceimpl.EmailServiceImpl;
import hu.diploma.android.serviceimpl.GroupServiceImpl;
import hu.diploma.android.serviceimpl.PersonServiceImpl;
import hu.diploma.android.serviceimpl.SmsMmsServiceImpl;
import hu.diploma.common.service.AddressService;
import hu.diploma.common.service.CallsService;
import hu.diploma.common.service.DeviceService;
import hu.diploma.common.service.EmailService;
import hu.diploma.common.service.GroupService;
import hu.diploma.common.service.PersonService;
import hu.diploma.common.service.PersonalDataService;
import hu.diploma.common.service.ServiceProvider;
import hu.diploma.common.service.SmsMmsService;
import hu.diploma.common.service.StructuredNameService;
import hu.diploma.common.service.UserService;
import hu.diploma.common.vos.CallVo;
import hu.diploma.common.vos.EmailVo;
import hu.diploma.common.vos.GroupVo;
import hu.diploma.common.vos.SmsMmsVo;
import hu.diploma.common.vos.UserVo;

import java.util.List;

import android.content.ContentResolver;

public class ServiceProviderImpl implements ServiceProvider {

	public static final String PREFS_NAME = "ContanctManagerPrefs";
	private static ServiceProviderImpl instance;
	private ContentResolver contentResolver;
	private GroupService groupService;
	private CallsService callsService;
	private EmailService emailService;
	private SmsMmsService smsMmsService;
	private List<GroupVo> groupVos;

	private List<EmailVo> emailVos;
	private List<SmsMmsVo> smsMmsVos;
	private List<CallVo> callVos;
	private PersonService personService;

	private UserVo user;

	private int state;

	private ServiceProviderImpl() {

	}

	public synchronized static ServiceProviderImpl getInstance() {
		if (ServiceProviderImpl.instance == null) {
			ServiceProviderImpl.instance = new ServiceProviderImpl();
		}
		return ServiceProviderImpl.instance;
	}

	@Override
	public synchronized GroupService getGroupService() {
		if (groupService == null) {
			groupService = new GroupServiceImpl(getContentResolver());
		}
		return groupService;
	}

	@Override
	public synchronized CallsService getCallService() {
		if (callsService == null) {
			callsService = new CallsServiceImpl(getContentResolver());
		}
		return callsService;
	}

	@Override
	public synchronized EmailService getEmailService() {
		if (emailService == null) {
			emailService = new EmailServiceImpl(getContentResolver());
		}
		return emailService;
	}

	@Override
	public synchronized SmsMmsService getSmsMmsService() {
		if (smsMmsService == null) {
			smsMmsService = new SmsMmsServiceImpl(getContentResolver());
		}
		return smsMmsService;
	}

	public void setContentResolver(ContentResolver contentResolver) {
		this.contentResolver = contentResolver;
	}

	public ContentResolver getContentResolver() {
		return contentResolver;
	}

	public void setGroupVos(List<GroupVo> groupVos) {
		this.groupVos = groupVos;
	}

	public List<GroupVo> getGroupVos() {
		return groupVos;
	}

	public List<EmailVo> getEmailVos() {
		return emailVos;
	}

	public void setEmailVos(List<EmailVo> emailVos) {
		this.emailVos = emailVos;
	}

	public List<SmsMmsVo> getSmsMmsVos() {
		return smsMmsVos;
	}

	public void setSmsMmsVos(List<SmsMmsVo> smsMmsVos) {
		this.smsMmsVos = smsMmsVos;
	}

	public List<CallVo> getCallVos() {
		return callVos;
	}

	public void setCallVos(List<CallVo> callVos) {
		this.callVos = callVos;
	}

	@Override
	public UserService getUserService() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public DeviceService getDeviceService() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public AddressService getAddressService() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public PersonService getPersonService() {
		if (personService == null) {
			personService = new PersonServiceImpl(getContentResolver());
		}
		return personService;
	}

	@Override
	public PersonalDataService getPersonalDataService() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public StructuredNameService getStructuredNameService() {
		// TODO Auto-generated method stub
		return null;
	}

	public void setUser(UserVo user) {
		this.user = user;
	}

	public UserVo getUser() {
		return user;
	}

	public void setState(int state) {
		this.state = state;
	}

	public int getState() {
		return state;
	}

}
